package com.leather.express.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.leather.common.entity.Express;
import com.leather.express.vo.ExpressQueryVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
*  @author kevin
*/
public interface ExpressMapper extends BaseMapper<Express> {


    @Select("select a.*,b.nick_name,b.img_url from express a,user b where a.user_id = b.id and a.get_flag = 0  order by a.id desc limit #{pageId},20")
    List<ExpressQueryVo> queryIndex(@Param("pageId") int pageId);

    @Select("select a.*,b.nick_name,b.img_url from express a,user b where a.user_id = b.id  and a.get_user_id = #{userId}  order by a.id desc limit #{pageId},20")
    List<ExpressQueryVo> queryUserOrder(@Param("pageId") int pageId, @Param("userId") int userId);


    @Select("select a.*,b.nick_name,b.img_url from express a,user b where a.user_id = b.id  and a.user_id = #{userId}  order by a.id desc limit #{pageId},20")
    List<ExpressQueryVo> queryUserExpress(@Param("pageId") int pageId, @Param("userId") int userId);

    @Select("select a.*,b.nick_name,b.img_url from express a,user b where a.user_id = b.id and a.get_flag = 0 and (a.type like concat('%',#{searchValue},'%') or  " +
            " a.get_address like concat('%',#{searchValue},'%') )  order by a.id desc")
    List<ExpressQueryVo> search(@Param("searchValue") String searchValue);


    @Select("select * from express where id = #{expressId} for update")
    Express getExpressById(@Param("expressId") int expressId);

    @Update("update express set get_user_id = #{getUserId},get_flag = 1,get_time=now() where id  = #{id} and get_flag = 0")
    int updateExpressById(@Param("id") int id,@Param("getUserId") int getUserId);

    @Delete("delete from express where id = #{id} and user_id = #{userId} and get_flag = 0")
    int delelteExpressById(@Param("id") int id, @Param("userId") int userId);

}